{layout name="layout/food" /}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div id="my-form" class="widget am-cf">
                    <div class="widget-body am-form tpl-form-line-form">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">V1等级</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">所需积分</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" min="0" class="tpl-form-input" v-model="gift[0].score" disabled>
                                    <small>设置该等级所需要的积分，消费1元=1积分</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">升级赠券</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <div class="widget-become-goods am-form-file am-margin-top-xs">
                                        <button type="button" class="upload-file am-btn am-btn-secondary am-radius" @click.stop="onSelect(0)">
                                            <i class="am-icon-cloud-upload"></i> 选择优惠券
                                        </button>
                                        <div class="coupon-list uploader-list am-cf">
                                            <div v-for="(item,index) in gift[0].gift" class="file-item">
                                                <i class="iconfont iconshanchu item-delete am-fr"  @click="onDelele(index,0)"></i>
                                                <div><img :src="item.image"></div>
                                                <div style="text-align: center;"><small>{{item.name}}</small></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">V2等级</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">所需积分</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" min="0" class="tpl-form-input" v-model="gift[1].score" required>
                                    <small>设置该等级所需要的积分，消费1元=1积分</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">升级赠券</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <div class="widget-become-goods am-form-file am-margin-top-xs">
                                        <button type="button" class="upload-file am-btn am-btn-secondary am-radius" @click.stop="onSelect(1)">
                                            <i class="am-icon-cloud-upload"></i> 选择优惠券
                                        </button>
                                        <div class="coupon-list uploader-list am-cf">
                                            <div v-for="(item,index) in gift[1].gift" class="file-item">
                                                <i class="iconfont iconshanchu item-delete am-fr"  @click="onDelele(index,1)"></i>
                                                <div><img :src="item.image"></div>
                                                <div style="text-align: center;"><small>{{item.name}}</small></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">V3等级</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">所需积分</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" min="0" class="tpl-form-input" v-model="gift[2].score" required>
                                    <small>设置该等级所需要的积分，消费1元=1积分</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">升级赠券</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <div class="widget-become-goods am-form-file am-margin-top-xs">
                                        <button type="button" class="upload-file am-btn am-btn-secondary am-radius" @click.stop="onSelect(2)">
                                            <i class="am-icon-cloud-upload"></i> 选择优惠券
                                        </button>
                                        <div class="coupon-list uploader-list am-cf">
                                            <div v-for="(item,index) in gift[2].gift" class="file-item">
                                                <i class="iconfont iconshanchu item-delete am-fr"  @click="onDelele(index,2)"></i>
                                                <div><img :src="item.image"></div>
                                                <div style="text-align: center;"><small>{{item.name}}</small></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">V4等级</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">所需积分</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" min="0" class="tpl-form-input" v-model="gift[3].score" required>
                                    <small>设置该等级所需要的积分，消费1元=1积分</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">升级赠券</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <div class="widget-become-goods am-form-file am-margin-top-xs">
                                        <button type="button" class="upload-file am-btn am-btn-secondary am-radius" @click.stop="onSelect(3)">
                                            <i class="am-icon-cloud-upload"></i> 选择优惠券
                                        </button>
                                        <div class="coupon-list uploader-list am-cf">
                                            <div v-for="(item,index) in gift[3].gift" class="file-item">
                                                <i class="iconfont iconshanchu item-delete am-fr"  @click="onDelele(index,3)"></i>
                                                <div><img :src="item.image"></div>
                                                <div style="text-align: center;"><small>{{item.name}}</small></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">V5等级</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">所需积分</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" min="0" class="tpl-form-input" v-model="gift[4].score" required>
                                    <small>设置该等级所需要的积分，消费1元=1积分</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">升级赠券</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <div class="widget-become-goods am-form-file am-margin-top-xs">
                                        <button type="button" class="upload-file am-btn am-btn-secondary am-radius" @click.stop="onSelect(4)">
                                            <i class="am-icon-cloud-upload"></i> 选择优惠券
                                        </button>
                                        <div class="coupon-list uploader-list am-cf">
                                            <div v-for="(item,index) in gift[4].gift" class="file-item">
                                                <i class="iconfont iconshanchu item-delete am-fr"  @click="onDelele(index,4)"></i>
                                                <div><img :src="item.image"></div>
                                                <div style="text-align: center;"><small>{{item.name}}</small></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">V6等级</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">所需积分</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" min="0" class="tpl-form-input" v-model="gift[5].score" required>
                                    <small>设置该等级所需要的积分，消费1元=1积分</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">升级赠券</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <div class="widget-become-goods am-form-file am-margin-top-xs">
                                        <button type="button" class="upload-file am-btn am-btn-secondary am-radius" @click.stop="onSelect(5)">
                                            <i class="am-icon-cloud-upload"></i> 选择优惠券
                                        </button>
                                        <div class="coupon-list uploader-list am-cf">
                                            <div v-for="(item,index) in gift[5].gift" class="file-item">
                                                <i class="iconfont iconshanchu item-delete am-fr"  @click="onDelele(index, 5)"></i>
                                                <div><img :src="item.image"></div>
                                                <div style="text-align: center;"><small>{{item.name}}</small></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-2 am-margin-top-lg">
                                    <button @click.stop="onSubmit" type="button" class="am-btn am-btn-xs am-btn-secondary">
                                        提交保存
                                    </button>
                                </div>
                            </div>
                        </fieldset>
                    </div>
            </div>
        </div>
    </div>
</div>
<script src="/assets/plugins/vue/vue.min.js"></script>
<script src="/addons/food/js/select.data.js"></script>
<script>
    $(function () {
        const vue = new Vue({
            el: '#my-form',
            data: {
                gift: <?= json_encode($model) ?>
            },
            methods: {
                setGift:function(db,lv){
                    let gift = this.gift;
                    if(!gift[lv].gift){
                        newGift = [];
                    }else{
                        newGift = gift[lv].gift;
                    }
                    db.forEach(function(item) {
                        newGift.push(item)
                    });
                    Vue.set(this.gift[lv],'gift',newGift);
                },
                //删除组件数据项目
                onDelele: function(index, lv) {
                    let gift = this.gift;
                    gift[lv].gift.splice(index, 1);
                    this.gift = gift;
                },
                //获取优惠券列表
                onSelect: function(lv) {
                    $.selectData({
                        title: '选择优惠券',
                        uri: 'coupon/lists',
                        duplicate: false,
                        dataIndex: 'id',
                        done: function(data) {
                            vue.setGift(data,lv);
                        }
                    });
                },

                //提交保存
                onSubmit: function() {
                    $.post('', {
                        data: this.gift
                    }, function(result) {
                        result.code === 1 ? $.show_success(result.msg, result.url) : $.show_error(result.msg)
                    })
                }
            }
        });
    });

</script>